// 导入express
const express = require("express");
// 导入ejs
const ejs = require("ejs");
// 导入express-session
const expressSession = require("express-session");
// 导入帐号啊信息数据库
const users = require("./database/model/userModel");
// const songs = require("./database/model/songModel");
// 导入验证模块
const verifySession = require("./middlewares/verify-session");
// 导入路由
const userRouter = require("./routers/userPage");
const apiRouter = require("./routers/apiRouter");
const { get } = require("mongoose");
// 创建服务器对象
const app = express();
// 中间件使用
app.set("views",__dirname+"/html");
app.engine("html",ejs.renderFile);
app.use(express.static(__dirname+"/public"));
app.use(express.urlencoded({extended:false}));
app.use(expressSession({
    name:"id01",
    secret: "chenzhen",
    saveUninitialized: true,
    resave:false,
    cookie:{
        httpOnly:true,
        maxAge:1000*60*60
    }
}));
// 设置一个初始页
app.get("/",(req,res)=>{
    res.render("login.html",{warning1:""});
})
app.use(apiRouter);
app.use(verifySession,userRouter);
// 监听服务
app.listen(80,()=>{
    console.log("服务器启动成功!");
})